/**
 * Created by dale on 2017/10/20.
 */
function openit(target){
    var obj = $(target).clone();
    obj.find(':nth-child(n)').remove();
    var text = obj.html();
    var id     = $(target).attr('nodeId');
    var noType = $(target).attr('nodeType');
    if(noType == 'plans'){
        if($(target).find('.m-badge').text()=='缴费程序'){
            $('#targetFrame',window.parent.document).attr('src',baseUrl+'mobile/backlog/nodeFinance?iBPCId='+id);
        }else {
            $('#targetFrame',window.parent.document).attr('src',baseUrl+'mobile/backlog/nodeDetail?iBPCId='+id);
        }
    }else if (noType == 'applyTab'){
        $('#targetFrame',window.parent.document).attr('src',baseUrl+'mobile/backlog/applyTab?iRTId='+id+'&type='+$(target).attr('applyType'));
    } else if(noType == 'carRoute'){
        $('#targetFrame',window.parent.document).attr('src',baseUrl+'mobile/backlog/carDetail?iUCId='+id+'&hideButton=true');
    } else {
        $('#targetFrame',window.parent.document).attr('src',baseUrl+'mobile/backlog/carDetail?iUCId='+id);
    }
    window.parent.setTitle(text);
    window.parent.goTarget();
}

try{
    window.top.chageColor('#0066cc');
    // window.webkit.messageHandlers.setBarColor.postMessage({color:'#0066cc'});
}catch (Expection){

}

$.ajax({
    url:baseUrl+'mobile/backlog/init',
    type:'POST',
    dataType:'json',
    success:function (data) {
        var str = '';
        if(data['applyTab'].length>0){
            str += '<li nodeId="applyTab" class="m-list-group">平板申领</li>';
            $.each(data['applyTab'], function (id,item) {
                str += '<li><a  nodeType="applyTab" nodeId="'+item['iRTId']+'" applyType="'+item['iType']+'" href="javascript:void(0)" onclick="openit(this)">'+(item['sSchoolName'] == undefined ? '自用' : item['sSchoolName'] ) +'<div class="m-right" ><span  class="m-badge c2">申领确认-'+item['typeName']+'</span></div></a></li>';
            });
        }
        if(data['carRoute'].length > 0) {
            str += '<li nodeId="applyTab" class="m-list-group">我的行程</li>';
            $.each(data['carRoute'], function (id,item) {
                str += '<li><a  nodeType="carRoute" nodeId="'+item['iUCId']+'"  href="javascript:void(0)" onclick="openit(this)">预计时间:'+item['tStartTime']+'~'+item['tEndTime']+'</a></li>';
            });
        }
        if(data['plans'].length>0){
            str += '<li nodeId="plans" class="m-list-group">流程计划</li>';
            $.each(data['plans'],function (id,item) {
                if(item['color']=='red'){
                    str+='<li><a  nodeType="plans" nodeId="'+item['iBPCId']+'" href="javascript:void(0)" onclick="openit(this)">'+item['sSchoolName']+'<div class="m-right" ><span  class="m-badge">'+item['sNodeName']+'</span></div></a></li>';
                }else {
                    str+='<li><a  nodeType="plans" nodeId="'+item['iBPCId']+'" href="javascript:void(0)" onclick="openit(this)">'+item['sSchoolName']+'<div class="m-right" ><span  class="m-badge c2">'+item['sNodeName']+'</span></div></a></li>';
                }
            });
        }
        if(data['useCar'].length>0){
            str += '<li nodeId="useCar" class="m-list-group">用车审批</li>';
            $.each(data['useCar'],function (id,item) {
                if(item['iCarId'] == null){
                    str+='<li><a  nodeType="useCar" nodeId="'+item['iUCId']+'" href="javascript:void(0)" onclick="openit(this)">'+item['sDepName']+item['userName']+'<div class="m-right" ><span  class="m-badge c2">申请私车</span></div></a></li>';
                }else {
                    str+='<li><a  nodeType="useCar" nodeId="'+item['iUCId']+'" href="javascript:void(0)" onclick="openit(this)">'+item['sDepName']+item['userName']+'<div class="m-right" ><span  class="m-badge c1">申请公车</span></div></a></li>';
                }

            });
        }
        $('.m-list').append(str);


        // attendDetail.datagrid('reload');
        // staffList.addDataGridParams({depId:currentDepId}).datagrid('getPanel').panel('setTitle', '职工列表（' + row['sDepName'] + '）');
    },
    error:function (data) {
        console.log(data);
    }
});